package com.sky.local_ads.servicemanager;

import android.app.Activity;

import com.sky.local_ads.constants.ServiceConstants;
import com.sky.local_ads.listener.ResponseListener;
import com.sky.local_ads.listener.ServiceResponseListener;
import com.sky.local_ads.networkmanager.HttpVerb;
import com.sky.local_ads.networkmanager.NetworkManager;
import com.sky.local_ads.networkmanager.ServiceRequest;
import com.sky.local_ads.store_list.StoreResponse;
import com.sky.local_ads.store_offers.StoreOfferResponse;

public class ServiceManager {
	
	public static void getStoreList(Activity activity,final ServiceResponseListener<StoreResponse> listener){
	ServiceRequest request=new ServiceRequest.Builder("http://10.0.2.2/local_ads/store_list.php").verb(HttpVerb.GET).build();
	try{
		NetworkManager.executeJsonAsync(request, StoreResponse.class, new ResponseListener<StoreResponse>() {

			@Override
			public void onSuccess(StoreResponse response) {
				listener.onSuccess(response);
			}

			@Override
			public void onFailure(Throwable throwable, String errorResponse) {
				listener.onFailure(throwable, errorResponse);
			}
		});
		
	}catch(Exception e){
		listener.onFailure(e.getCause(),ServiceConstants.NETWORk_ERROR );
	}
	}

	public static void getStoreOffers(Activity activity,String businessId,final ServiceResponseListener<StoreOfferResponse> listener){
		String targetURL=null;
		if(businessId!=null){
			targetURL="http://10.0.2.2/local_ads/store_offers.php?business_id="+businessId;
		}
		
		ServiceRequest request=new ServiceRequest.Builder(targetURL).verb(HttpVerb.GET).build();
		try{
			NetworkManager.executeJsonAsync(request, StoreOfferResponse.class, new ResponseListener<StoreOfferResponse>() {

				@Override
				public void onSuccess(StoreOfferResponse response) {
					listener.onSuccess(response);
				}

				@Override
				public void onFailure(Throwable throwable, String errorResponse) {
					String s=errorResponse;
					s.toString();
				}
			});
			
		}catch(Exception e){
			listener.onFailure(e.getCause(),ServiceConstants.NETWORk_ERROR );
		}
		}
	
}
